package java101;

public class Dollar {

	public static void main(String[] args) {

		int p;
		int n;
		int d;
		int q;

		int counter = 0; //Counts the number of combinations that = 100.
		int tries = 0; //Counts the number of combinations that != 100.

		/*
		 * Create 4 nested for loops decrementing the number of coins. If the
		 * number of coins equals 100, then print the combination and add one to
		 * the counter. Otherwise, add one to the variable "tries". Once all
		 * combinations are complete, print the number of combinations, and the
		 * number of tries (fails + successes).
		 */

		for (p = 100; p >= 0; p--) {

			for (n = 20; n >= 0; n--) {

				for (d = 10; d >= 0; d--) {

					for (q = 4; q >= 0; q--) {

						if ((p + (n * 5) + (d * 10) + (q * 25)) == 100) {

							String formatP = String.format("%d pennies\t", p);
							String formatN = String.format("%d nickels\t", n);
							String formatD = String.format("%d dimes\t", d);
							String formatQ = String.format("%d quarters\t", q);

							if (p != 0)
								System.out.println(formatP);
							if (n != 0)
								System.out.println(formatN);
							if (d != 0)
								System.out.println(formatD);
							if (q != 0)
								System.out.println(formatQ);

							System.out.println("\n");
							counter++;
						}

						else {
							tries++;
						}
					}
				}
			}
		}

		String formatOut = String
				.format("I found %d ways to make change for a dollar in only %d attempts!",
						counter, tries + counter);

		System.out.println(formatOut);
	}

}